package com.jammingpro.blog_system.mapper;

import com.jammingpro.blog_system.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BlogInfoMapper {
    @Select("select * from blog where delete_flag=0")
    List<BlogInfo> getBlogInfoList();

    @Select("select * from blog where delete_flag=0 and id=#{id}")
    BlogInfo getBlogInfoById(Integer id);

    @Insert("insert into blog(title, content, user_id) values(#{title}, #{content}, #{userId})")
    Integer insertBlogInfo(BlogInfo blogInfo);

    @Select("select user_id from blog where delete_flag=0 and id=#{blogId}")
    Integer getAuthorIdByBlogId(Integer blogId);

    @Update("update blog set delete_flag=1 where id=#{blogId}")
    Integer deleteBlogByBlogId(Integer blogId);

    @Update("update blog set title=#{title}, content=#{content} where delete_flag=0 and id=#{id}")
    Integer updateBlogInfo(BlogInfo blogInfo);
}
